<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">渠道管理</ui:define>
    <ui:define name="content">
        <h:form>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="right">
                        <p:commandButton value="编辑" icon="fa fa-edit"
                                         actionListener="#{channelInfoBean.changeStatusToEdit}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{channelInfoBean.isView() and security:areAllGranted('CHANNEL_PRODUCT_CHANNEL_EDIT')}"/>
                        <p:commandButton value="批量新增"
                                         action="#{channelInfoBean.onBatchAdd}"
                                         rendered="#{channelInfoBean.isNormal()}"
                                         update="@form"
                                         process="@this">
                            <f:setPropertyActionListener value="/views/channel/channel/info.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                        <p:commandButton value="保存" icon="fa fa-save"
                                         actionListener="#{channelInfoBean.onSave}"
                                         rendered="#{channelInfoBean.isNotView() and security:areAnyGranted('CHANNEL_PRODUCT_CHANNEL_EDIT,CHANNEL_PRODUCT_CHANNEL_ADD')}"
                                         update="@form"/>
                        <p:commandButton value="取消" icon="fa fa-reply"
                                         actionListener="#{channelInfoBean.changeStatusToView}"
                                         rendered="#{channelInfoBean.isEdit()}"
                                         process="@this"
                                         update="@form"/>
                        <p:button value="返回" icon="fa fa-reply-all" href="#{currentUserBean.back}"/>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>渠道信息</h1>
                            <p:panelGrid columns="4"
                                         columnClasses="ui-grid-col-2,ui-grid-col-4,ui-grid-col-2,ui-grid-col-4"
                                         layout="grid" styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">
                                <p:outputLabel for="channelCode" value="渠道编号"/>
                                <p:inputText id="channelCode" value="#{channelInfoBean.$.channelCode}"
                                             disabled="#{channelInfoBean.isView()}"/>

                                <p:outputLabel for="channelName" value="渠道名称"/>
                                <p:inputText id="channelName" value="#{channelInfoBean.$.channelName}"
                                             disabled="#{channelInfoBean.isView()}"/>

                                <p:outputLabel for="product" value="所属产品"/>
                                <p:selectOneMenu id="product" value="#{channelInfoBean.$.productId}" filter="true"
                                                 filterMatchMode="contains" disabled="#{channelInfoBean.isView()}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems value="#{channelInfoBean.commProductIds}" var="product"
                                                   itemLabel="#{product.name}"
                                                   itemValue="#{product.productId}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="channelGroup" value="渠道分类"/>
                                <p:selectOneMenu id="channelGroup" value="#{channelInfoBean.$.channelGroup}"
                                                 filter="true" filterMatchMode="contains"
                                                 disabled="#{channelInfoBean.isView()}">
                                    <p:ajax event="change" listener="#{channelInfoBean.onChangeChannelGroup()}"
                                            update="secondaryChannelGroup"/>
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems value="#{channelInfoBean.dictionaries[DictionaryCode.CHANNEL_GROUP]}"
                                                   var="dic"
                                                   itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="secondaryChannelGroup" value="二级渠道分类"/>
                                <p:selectOneMenu id="secondaryChannelGroup" value="#{channelInfoBean.$.secondaryChannelGroup}"
                                                 filter="true" filterMatchMode="contains"
                                                 disabled="#{channelInfoBean.isView()}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems value="#{channelInfoBean.secondaryChannelGroups}"
                                                   var="dic"
                                                   itemLabel="#{dic.channelName}" itemValue="#{dic.id}"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>